#ifndef MYRECTANGLE_H
#define MYRECTANGLE_H

#include <QGraphicsItem>

class MyRectangle : public QObject, public QGraphicsItem // 双继承
{
    Q_OBJECT
public:
    MyRectangle(); // 自动生成的构造函数

    QPointF mspt, mept; // 定义了矩形的两个对角点

    // QGraphicsItem interface
public:
    QRectF boundingRect() const override;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;

    void DrawSnapRect(QPainter *painter, QPointF cpt);

protected:
    void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
    void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;

public:
    QPainterPath shape() const override;

private:
    bool isClickOnBorder(const QPointF &localPos) const; // 判断是否点击在边缘
};

#endif // MYRECTANGLE_H
